# -*- coding: utf-8 -*-
# @Time    : 2021/5/17 17:28
# @Author  : xxue
# @Email   : x_xue1212@163.com
# @File    : 回合制对战游戏.py
# @Software: PyCharm

# 创建角色：名字、性别、血量、装备
# 创建房间：
#     角色可加入房间
#     房间内的人可互打
#     房间上限2人
#     装备-防弹衣
#     血量默认100
#     正常被攻击-10滴血
#     有防弹衣-5滴血

class User():
    energy = 100

    def __init__(self, name, sex, equipment):
        self.name = name
        self.sex = sex
        self.equipment = equipment

    def combat(self,enemy):
        if self.equipment =="防弹衣":
            hurted = 5
        else:
            hurted = 10
        self.energy -= hurted
        print(f"{self.name}受到{hurted}伤害")
        if self.energy<=0:
            print(f"游戏结束,{self.name}败".center(30,"*"))
            return 1



class room:
    print(f"1v1大战即将开始".center(30,"*"))
    def __init__(self, name):
        self.name = name
        self.name_list = []
    def room_add(self,username):
        if len(self.name_list) <2:
            if username in self.name_list:
                print(f"{username}已存在")
            else:
                self.name_list.append(username)
                print(f"欢迎{username}加入{self.name}")
        else:
            print(f"{self.name}人数大于2,{username}无法加入房间")


player1 = User("张仁杰", "male", "防弹衣")
player2 = User("李璐", "male", "")
player3 = User("罗干", "male", "")
room1 = room("1v1大战房间")
room1.room_add(player1.name)
room1.room_add(player2.name)
room1.room_add(player3.name)
while 1:
    if player1.combat(player2):
        break
    if player2.combat(player2):
        break
